﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tui_xiang_zi
{
    class Program
    {
            static void cz(int[,] map)
        {
            if(map[4,1]==4 )
            {
                map[4, 1] = 2; 
            }
            if (map[4, 2] == 4)
            {
                map[4, 2] = 2;
            }
            if (map[4, 3] == 4)
            {
                map[4, 3] = 2;
            }
            if (map[5, 1] == 4)
            {
                map[5, 1] = 2;
            }
            if (map[6, 1] == 4)
            {
                map[6, 1] = 2;
            }
            if (map[7, 1] == 4)
            {
                map[7, 1] = 2;
            }
            if (map[8, 1] == 4)
            {
                map[8, 1] = 2;
            }
            if (map[8, 2] == 4)
            {
                map[8, 2] = 2;
            }
            if (map[8, 3] == 4)
            {
                map[8, 3] = 2;
            }
            if (map[4, 1] == 0)
            {
                map[4, 1] = 2;
            }
            if (map[4, 2] == 0)
            {
                map[4, 2] = 2;
            }
            if (map[4, 3] == 0)
            {
                map[4, 3] = 2;
            }
            if (map[5, 1] == 0)
            {
                map[5, 1] = 2;
            }
            if (map[6, 1] == 0)
            {
                map[6, 1] = 2;
            }
            if (map[7, 1] == 0)
            {
                map[7, 1] = 2;
            }
            if (map[8, 1] == 0)
            {
                map[8, 1] = 2;
            }
            if (map[8, 2] == 0)
            {
                map[8, 2] = 2;
            }
            if (map[8, 3] == 0)
            {
                map[8, 3] = 2;
            }
        }
            static void xs(int [,]map)
        {
            for (int i = 0; i < 12; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    if (map[i, j] == 0)
                    {
                        Console.Write("  ");
                    }
                    else if (map[i, j] == 1)
                    {
                        Console.Write("■");
                    }
                    else if (map[i, j] == 2)
                    {
                        Console.Write("☆");
                    }
                    else if (map[i, j] == 3)
                    {
                        Console.Write("□");
                    }
                    else if (map[i, j] == 4)
                    {
                        Console.Write("Τ");
                    }
                    else if (map[i, j] == 5)
                    {
                        Console.Write("★");
                    }
                }
                Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {
            int score = 0;
            int[,] StartMap = new int[12, 13] {
                 {0,0,0,0,0,1,1,1,1,1,1,1,0},
                 {0,0,0,0,0,1,0,0,1,0,0,1,0},
                 {0,0,0,0,0,1,0,0,3,3,0,1,0},
                 {1,1,1,1,1,1,0,3,1,0,0,1,0},
                 {1,2,2,2,1,1,1,0,1,0,0,1,1},
                 {1,2,0,0,1,0,0,3,0,1,0,0,1},
                 {1,2,0,0,0,0,3,0,3,0,3,0,1},
                 {1,2,0,0,1,0,0,3,0,1,0,0,1},
                 {1,2,2,2,1,1,1,0,1,0,0,1,1},
                 {1,1,1,1,1,1,0,3,0,0,0,1,0},
                 {0,0,0,0,0,1,0,4,1,0,0,1,0},
                 {0,0,0,0,0,1,1,1,1,1,1,1,0}
             };
            int[,] map = new int[12, 13] {
                 {0,0,0,0,0,1,1,1,1,1,1,1,0},
                 {0,0,0,0,0,1,0,0,1,0,0,1,0},
                 {0,0,0,0,0,1,0,0,3,3,0,1,0},
                 {1,1,1,1,1,1,0,3,1,0,0,1,0},
                 {1,2,2,2,1,1,1,0,1,0,0,1,1},
                 {1,2,0,0,1,0,0,3,0,1,0,0,1},
                 {1,2,0,0,0,0,3,0,3,0,3,0,1},
                 {1,2,0,0,1,0,0,3,0,1,0,0,1},
                 {1,2,2,2,1,1,1,0,1,0,0,1,1},
                 {1,1,1,1,1,1,0,3,0,0,0,1,0},
                 {0,0,0,0,0,1,0,4,1,0,0,1,0},
                 {0,0,0,0,0,1,1,1,1,1,1,1,0}
             };
             int x = 10, y = 7;
            for (; ; )
            {
                if(map[4,1]==3&& map[4, 2] == 3 && map[4, 3] == 3 &&
                    map[5, 1] == 3 && map[6, 1] == 3 && map[7, 1] == 3 &&
                    map[8, 1] == 3 && map[8, 2] == 3 && map[8, 3] == 3 )
                {
                    score = 9;
                }
                xs(map);
                ConsoleKeyInfo aj = Console.ReadKey();
                Console.WriteLine();
                cz(map);
                Console.Clear();
                if (score == 9)
                {
                    map[1, 6] = 5;
                }
                if (aj.Key.ToString() == "UpArrow")
                {
                    if (map[x - 1, y] == 0 || map[x - 1, y] == 3)//遇到箱子或者空地
                    {
                        if (map[x - 1, y] == 0)//空地前进
                        {
                            map[x - 1, y] = 4;
                            map[x, y] = 0;
                            x--;
                        }
                        else if (map[x - 1, y] == 3)//箱子
                        {
                            if (map[x - 2, y] == 0)//空地前进
                            {
                                map[x - 2, y] = 3;
                                map[x - 1, y] = 4;
                                map[x, y] = 0;
                                x--;
                            }
                            else if (map[x - 2, y] == 2)//遇到星星 加分前进
                            {
                                map[x - 2, y] = 3;
                                map[x - 1, y] = 4;
                                map[x, y] = 0;
                                x--;
                            }
                            else//其他不动
                            {
                                Console.Clear();
                                continue;
                            }
                        }
                    }
                    else if (map[x - 1, y] == 2)//遇到星星 
                    {
                        map[x - 1, y] = 4;
                        map[x, y] = 0;
                        x--;
                    }
                    else if (map[x - 1, y] == 1)//遇到墙壁
                    {
                        Console.Clear();
                        continue;
                    }
                    else if (map[x - 1, y] == 5)//遇到终点判断是否吃满星星 吃满前进 没吃满不动
                    {
                        if (score == 9)
                        {
                            break;
                        }
                        else
                        {
                            Console.Clear();
                            continue;
                        }
                    }
                }
                else if (aj.Key.ToString() == "DownArrow")
                {
                    if (map[x + 1, y] == 0 || map[x + 1, y] == 3)//遇到箱子或者空地
                    {
                        if (map[x + 1, y] == 0)//空地前进
                        {
                            map[x + 1, y] = 4;
                            map[x, y] = 0;
                            x++;
                        }
                        else if (map[x + 1, y] == 3)//箱子
                        {
                            if (map[x + 2, y] == 0)//空地前进
                            {
                                map[x + 2, y] = 3;
                                map[x + 1, y] = 4;
                                map[x, y] = 0;
                                x++;
                            }
                            else if (map[x + 2, y] == 2)//遇到星星 加分前进
                            {
                                map[x + 2, y] = 3;
                                map[x+1, y] = 4;
                                map[x, y] = 0;
                                x++;
                            }
                            else//其他不动
                            {
                                Console.Clear();
                                continue;
                            }
                        }
                    }
                    else if (map[x + 1, y] == 2)//遇到星星 
                    {
                        map[x + 1, y] = 4;
                        map[x, y] = 0;
                        x++;
                    }
                    else if (map[x + 1, y] == 1)//遇到墙壁
                    {
                        Console.Clear();
                        continue;
                    }
                    else if (map[x + 1, y] == 5)//遇到终点判断是否吃满星星 吃满前进 没吃满不动
                    {
                        if (score == 9)
                        {
                            break;
                        }
                        else
                        {
                            Console.Clear();
                            continue;
                        }
                    }
                }
                else if (aj.Key.ToString() == "LeftArrow")
                {
                    if (map[x, y-1] == 0 || map[x, y-1] == 3)//遇到箱子或者空地
                    {
                        if (map[x , y-1] == 0)//空地前进
                        {
                            map[x , y-1] = 4;
                            map[x, y] = 0;
                            y--;
                        }
                        else if (map[x, y-1] == 3)//箱子
                        {
                            if (map[x, y-2] == 0)//空地前进
                            {
                                map[x, y-2] = 3;
                                map[x, y-1] = 4;
                                map[x, y] = 0;
                                y--;
                            }
                            else if (map[x, y - 2] == 2)//遇到星星 加分前进
                            {
                                map[x, y - 2] = 3;
                                map[x, y-1] = 4;
                                map[x, y] = 0;
                                y--;
                            }
                            else//其他不动
                            {
                                Console.Clear();
                                continue;
                            }
                        }
                    }
                    else if (map[x , y-1] == 2)//遇到星星 
                    {
                        map[x , y-1] = 4;
                        map[x, y] = 0;
                        y--;
                    }
                    else if (map[x , y-1] == 1)//遇到墙壁
                    {
                        Console.Clear();
                        continue;
                    }
                    else if (map[x , y-1] == 5)//遇到终点判断是否吃满星星 吃满前进 没吃满不动
                    {
                        if (score == 9)
                        {
                            break;
                        }
                        else
                        {
                            Console.Clear();
                            continue;
                        }
                    }
                }
                else if (aj.Key.ToString() == "RightArrow")
                {
                    if (map[x, y + 1] == 0 || map[x, y + 1] == 3)//遇到箱子或者空地
                    {
                        if (map[x, y + 1] == 0)//空地前进
                        {
                            map[x, y + 1] = 4;
                            map[x, y] = 0;
                            y++;
                        }
                        else if (map[x, y + 1] == 3)//箱子
                        {
                            if (map[x, y + 2] == 0)//空地前进
                            {
                                map[x, y + 2] = 3;
                                map[x, y + 1] = 4;
                                map[x, y] = 0;
                                y++;
                            }
                            else if (map[x, y + 2] == 2)//遇到星星 加分前进
                            {
                                map[x, y + 2] = 3;
                                map[x, y+1] = 4;
                                map[x, y] = 0;
                                y++;
                            }
                            else//其他不动
                            {
                                Console.Clear();
                                continue;
                            }
                        }
                    }
                    else if (map[x, y+1] == 2)//遇到星星 
                    {
                        map[x , y+1] = 4;
                        map[x, y] = 0;
                        y++;
                    }
                    else if (map[x, y +1] == 1)//遇到墙壁
                    {
                        Console.Clear();
                        continue;
                    }
                  
                    else if (map[x, y + 1] == 5)//遇到终点判断是否吃满星星 吃满前进 没吃满不动
                    {
                        if (score == 9)
                        {
                            break;
                        }
                        else
                        {
                            Console.Clear();
                            continue;
                        }
                    }
                }
                else if (aj.Key.ToString() == "F5")
                {
                    Array.Copy(StartMap,map,StartMap.Length);
                    x = 10; y = 7;
                }
            }
        }
    }
}
